package com.yuer.service.mian;

import com.yuer.service.HelloService;
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;

import java.util.ServiceLoader;
import java.util.Set;

public class MainTest {
    public static void main(String[] args) {
        // dubbo自己的实现机制，原声的肯定是拿不到的
//        ServiceLoader<HelloService> serviceLoader = ServiceLoader.load(HelloService.class);
//        System.out.println("provider:  " +serviceLoader.stream().distinct());
//        serviceLoader.forEach(helloService -> helloService.sayHello("jijiji"));

        ExtensionLoader<HelloService> extensionLoader = ExtensionLoader.getExtensionLoader(HelloService.class);
        Set<String> supportedExtensions = extensionLoader.getSupportedExtensions();
        for (String str:supportedExtensions){
            String result = extensionLoader.getExtension(str).sayHello("帅哥们");
            System.out.println(result);
        }


        //
        URL rul = URL.valueOf("test://www.baidu.com?hello.service=pig");
        HelloService adaptiveExtenSsion = ExtensionLoader.getExtensionLoader(HelloService.class).getAdaptiveExtension();
        System.out.println(adaptiveExtenSsion.sayHello(rul));

        URL rul2 = URL.valueOf("http://www.baidu.com?hello.service=pig");
        HelloService adaptiveExtenSsion2 = ExtensionLoader.getExtensionLoader(HelloService.class).getAdaptiveExtension();
        System.out.println(adaptiveExtenSsion2.sayHello(rul2));
    }
}
